﻿using Idte.Common.Process;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Idte.Application.Core.Flow
{
    public class StepByStepFlow : IControlFlow
    {
        IEnumerator<IStepDescriptor> enumerator;
        
        IProcessDescriptor processDescriptor;
        public StepByStepFlow(IProcessDescriptor processDescriptor)
        {
            this.processDescriptor = processDescriptor;
            this.enumerator = processDescriptor.Steps.OrderBy(m => m.Sequence).GetEnumerator();
        }

        public bool IsStepWise { get { return true;  } }
        public IStepDescriptor Current
        {
            get { return enumerator.Current; }
        }

        public void Dispose()
        {
            enumerator.Dispose();
        }

        object System.Collections.IEnumerator.Current
        {
            get { return enumerator.Current; }
        }

        public bool MoveNext()
        {
            PrepareDataFlow();
            return enumerator.MoveNext();
        }

        public bool MoveNext(IExecutionContext context)
        {
            return MoveNext();
        }

        public void Reset()
        {
            enumerator.Reset();
        }

        protected virtual void PrepareDataFlow()
        {

        }
    }
}
